<template>
  <div class="app-container">
    <el-form
      ref="queryForm"
      :model="queryParams"
      :inline="true"
      label-width="68px"
      class="query-form"
    >
      <el-form-item label="事件类型" prop="eventType">
        <el-select v-model="queryParams.eventType" placeholder="请选择事件类型" clearable size="small">
          <el-option
            v-for="dict in monitorEventType"
            :key="dict.diceValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="设备名称" prop="equName">
        <el-input
          v-model="queryParams.equName"
          placeholder="请输入设备名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="隧道id" prop="tunnelId">
        <el-input
          v-model="queryParams.tunnelId"
          placeholder="请输入隧道id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="隧道名称" prop="tunnelName">
        <el-input
          v-model="queryParams.tunnelName"
          placeholder="请输入隧道名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="报警时间" prop="warningTime">
        <el-date-picker
          v-model="queryParams.warningTime"
          clearable
          size="small"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择报警时间"
        />
      </el-form-item> -->
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
          <el-option label="待处理" value="0" />
          <el-option label="不予处理" value="1" />
          <el-option label="已处理" value="2" />
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="处理人员" prop="updateUser">
        <el-input
          v-model="queryParams.updateUser"
          placeholder="请输入处理人员"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <div class="content-container height_100-query_from">
      <div class="handle_bar">
        <div class="tit"><span>事件列表</span></div>
        <div>
          <!--  -->
        </div>
      </div>
      <div class="flex-1" style="position: relative;overflow: hidden;">
        <div style="position: absolute;left: 0;top: 0;bottom: 0;right: 0;display: flex;flex-direction: column;overflow: hidden;">
          <el-table
            v-loading="loading"
            :data="monitorList"
            class="flex-1"
            height="250"
            style="width:100%;"
            @selection-change="handleSelectionChange"
          >
            <el-table-column label="报警类型" align="center" prop="eventType" />
            <el-table-column label="报警设备名称" align="center" prop="equName" />
            <el-table-column label="隧道名称" align="center" prop="tunnelName" />
            <el-table-column label="报警时间" align="center" prop="warningTime" width="180">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.warningTime, '{y}-{m}-{d}') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="状态" align="center" prop="status">
              <template slot-scope="scope">
                <span v-if="scope.row.status == 0" class="text-danger">待处理</span>
                <span v-if="scope.row.status == 1">不予处理</span>
                <span v-if="scope.row.status == 2" class="text-navy">已处理</span>
              </template>
            </el-table-column>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
              <template slot-scope="scope">
                <template v-if="scope.row.status == 0">
                  <el-button
                    :loading="scope.row.loading"
                    slot="reference"
                    size="mini"
                    type="text"
                    @click="handleEvent(scope.row,2)"
                  >处理</el-button>
                  <el-divider direction="vertical" />
                  <el-popconfirm
                    title="是否确认操作？"
                    placement="left-end"
                    @confirm="handleNohandle(scope.row)"
                  >
                    <el-button
                      slot="reference"
                      size="mini"
                      type="text"
                    >不予处理</el-button>
                  </el-popconfirm>
                  <el-divider direction="vertical" />
                </template>
                <el-button
                  slot="reference"
                  size="mini"
                  type="text"
                  @click="handleEvent(scope.row,1)"
                >查看</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
    <EventHandle ref="eventHandle" />
  </div>
</template>

<script>
import EventHandle from './components/EventHandle.vue'
import { listMonitor, getMonitor, delMonitor, addMonitor, updateMonitor } from '@/api/fjgs/warning/monitor/eventAlarm'

export default {
  name: 'Monitor',
  components: {
    EventHandle
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 事件监测预警表格数据
      monitorList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        eventType: null,
        equId: null,
        equName: null,
        tunnelId: null,
        tunnelName: null,
        warningTime: null,
        status: null,
        updateUser: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      monitorEventType: []
    }
  },
  created() {
    this.getList()
    this.getDicts('monitor_event_type').then(response => {
      this.monitorEventType = response.data
    })
  },
  methods: {
    handleEvent(row, type) {
      row.loading = true
      const id = row.id || this.ids
      getMonitor(id).then(response => {
        this.$refs.eventHandle.open(response.data, type)
      }).finally(() => {
        row.loading = false
      })
    },
    /** 修改按钮操作 */
    // handleView(row) {
    //   this.reset()
    //   const id = row.id || this.ids
    //   getMonitor(id).then(response => {
    //     this.form = response.data
    //     this.open = true
    //     this.title = '修改事件监测预警'
    //   })
    // },
    /** 查询事件监测预警列表 */
    getList() {
      this.loading = true
      listMonitor(this.queryParams).then(response => {
        this.monitorList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        eventType: null,
        equId: null,
        equName: null,
        tunnelId: null,
        tunnelName: null,
        warningTime: null,
        status: '0',
        updateUser: null,
        updateTime: null,
        remark: null
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    }
  }
}
</script>
